Gloomy-Networking Documentation

Start_Stop

Scripts associated with initialization and de-initialization are provided here


gnet_packet_layouts

Syntax:

gnet_packet_layouts();

Description:

This is a script that is empty by default but is called when the network is initialized, so you do not need to call this from anywhere. Here you will define your packet layouts that will be used to pack your data when you use gnet_packet_build(PacketType, data).

You should familiarize yourself with the buffer data types. Dont worry its not scary, it is how you can optimize the amount of bytes you send! Example data layout. Packet ID integers should be between 0 - 219 since 220-255 is reserved for system level packets.

Example:

// Example on how to define a packet made for sending x and y coordinates
enum PacketId { pos_update = 0, death_notification }
gnet_packet_layout_create(PacketId.pos_update, buffer_s32, buffer_s32);

Example:

// Example on how to define a packet made for sending a death notification of a specific client_id
enum PacketId { pos_update = 0, death_notification }
gnet_packet_layout_create(PacketId.death_notification, buffer_u8);

gnet_start_network

Syntax:

gnet_start_network(MaxConnections, ProtocolId, Port, Username);
Argument name Type Description
MaxConnections number the maximum connections you want to allow. For Client / Server, the Server would allow the number of players you want in a game. For the Client you would only want 1 connection. (To the server).
ProtocolId number This should be a number between 1 - 65535. The number doesnt matter, but you shouldnt ever change it after releasing a build of your game.
Port number The port to communicate through. Using a number below 0 will automatically look for a Port to use.
Username string Username to use over the network! You can use this for.. usernames in games or maybe identifying connections in a way other than connectionId

Returns: (boolean) True if the network was initialized properly, or false if it was not successful (Port not open?)

Description:

Creates everything you need for GloomyNetworking. Call this when you are ready to initialize your NetworkManager and socket. You should store the result of this call into a variable and handle it accordingly.

Example:

// Example server setup with a specified port
var result = gnet_start_network(10, 1232, 3000, "Server");

if (result == true)
// You are succesfully connected!
else
show_message("We were not able to establish the network listening at the port 3000");

Example:

// Example client setup with automatically assigned port
var result = gnet_start_network(10, 1232, -1, "GloomyToad");

if (result == true)
show_message("Your networking has been established on port " + string(global.gnet_myPort));
else
show_message("We could not establish a network. We could not find an available port automatically.");

gnet_stop_network

Syntax:

gnet_stop_network();

Description:

from all connections.